//
//  HomeCell.m
//  笔记1
//
//  Created by  on 2022/11/3.
//

#import "HomeCell.h"
@interface HomeCell()
@property (strong, nonatomic) IBOutlet UIView *bgView;
@property (strong, nonatomic) IBOutlet UIImageView *defaultImg;
@property (strong, nonatomic) IBOutlet UILabel *date;
@property (strong, nonatomic) IBOutlet UILabel *time;
@property (strong, nonatomic) IBOutlet UILabel *content;
@property (strong, nonatomic) IBOutlet UIImageView *img;
@property (strong, nonatomic) IBOutlet UILabel *type;


@end
@implementation HomeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (IBAction)actionForBtn:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.tag ==  201) {
        self.model.favorite = sender.selected;
        [NoteTool update:self.model complete:^(BOOL success) {
        }];
        return;
    }else if (sender.tag == 202){
        if (self.block) {
            self.block();
        }
    }
  
}
- (void)setModel:(Note *)model{
    _model = model;
    if (model==nil || model.isFile) {
        self.date.hidden = YES;
        self.time.hidden = YES;
        self.content.hidden = YES;
        self.type.text = model ? LS(model.name) : LS(@"新建");
        self.selectBtnW.constant = model ? 18 : 0;
        self.selectBtn.hidden = model ? NO : YES;
        self.favoriteBtn.hidden = model ? NO : YES;
        self.img.hidden = YES;
        self.bgView.borderWidth = 2;
        self.defaultImg.hidden = NO;
        self.defaultImg.image = model ? [UIImage imageNamed:@"文件夹_白"] : [UIImage imageNamed:@"加号"];
        self.favoriteBtn.selected = model ? model.favorite : NO;
        self.selectBtn.selected = model ? model.select : NO;
    }else if (model.isFile == NO){
        self.date.hidden = NO;
        self.time.hidden = NO;
        self.content.hidden = NO;
        self.type.text = LS(model.name);
        self.selectBtnW.constant = 18;
        self.selectBtn.hidden = NO;
        self.favoriteBtn.hidden = NO;
        self.img.hidden = NO;
        self.bgView.borderWidth = 0;
        self.defaultImg.hidden = YES;
        
        self.date.text = [NSDate transToDate:LS(@"yyyy年MM月dd日") :model.stamp];
        self.time.text = [NSDate transToDate:@"HH:mm" :model.stamp];
        self.content.text = model.content;
        self.img.image = [UIImage imageWithData:model.imgs[0]];
        self.favoriteBtn.selected = model.favorite;
        self.selectBtn.selected = model.select;
    }
}
@end
